package py.com.fms.utilities;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage.Severity;
import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;

import py.com.fms.exception.CommonException;
import py.com.fms.session.ServiceSqlMap;

@SuppressWarnings("unused")
@Name("dateAssistant")
@Scope(ScopeType.SESSION)
public class DateAssistant {
	
	/*****************************************************************************
	 * 
	 * @return
	 */
	
	// Used to get current date
	public static Date getCurrentDate() throws ParseException {
		Date date = new Date(System.currentTimeMillis());
		SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
		String stringdate = df.format(date);
		Date actualdate = df.parse(stringdate);
		return actualdate;
	}
	
	public static Date getCurrentDateTime() throws ParseException {
		Date date = new Date(System.currentTimeMillis());
		SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy:HH:mm:ss");
		String stringdate = df.format(date);
		Date datetime = df.parse(stringdate);
		return datetime;
	}
	
	public static Date getHoleDateTime() throws ParseException {
		Date datetime = new Date(System.currentTimeMillis());
		return datetime;
	}
	
	public boolean bettweenDates(Date date, Date startDate, Date endDate) {
		if ((date == startDate) || (date == endDate)) {
			return true;
		} else {
			if (date.after(startDate) && date.before(endDate)) {
				return true;
			} else {
				return false;
			}
		}

	}
	
	public static Date getDatePlusDay(Date pDate, Integer pPlus) throws ParseException {
		System.out.println("en getDatePlusDay... " + pDate.toString() + "  pPlus = " + pPlus.toString());
		Calendar cal = Calendar.getInstance();
		cal.setTime(pDate);
		cal.add( Calendar.DAY_OF_MONTH, pPlus.intValue());
		System.out.println("* 5");
		Date date = new Date();
		System.out.println("* 6");
		date = cal.getTime();
		System.out.println("Date is : " + date);
		SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy:HH:mm:ss");
		String stringdate = df.format(date);
		Date datetime = df.parse(stringdate);
		System.out.println("** return datetime = " + datetime.toString());
		return datetime;
	}

}
